import { createRouter, createWebHistory } from "vue-router";
import Layout from "@/views/Layout/index.vue";
import Brief from "@/views/Brief/index.vue";
import Theme from "@/views/Theme/index.vue";
import Login from "@/views/Login/index.vue";
import Technology from "@/views/Technology/index.vue";
import lbt from "@/views/Layout/LayoutLbt/viewpager.vue";
import { ElMessage } from "element-plus";
//routes相当于是一个大路由，然后里面全都是子路由
const routes = [
  {
    path: "/",
    component: Layout,
    children: [
      { path: "", component: lbt },
      { path: "/brief", component: Brief },
      { path: "/theme", component: Theme },
      { path: "/technology", component: Technology },
    ],
  },
  { path: "/login", component: Login },
];

const router = createRouter({
  history: createWebHistory(),
  routes,
  linkActiveClass: "ext",
});

router.beforeEach((to, from, next) => {
  if (!localStorage.getItem("token") && to.path !== "/login") {
    ElMessage({
      type: "warning",
      message: "出错了",
    });
    return next("/login");
  }
  next();
});

export default router;
